import router  from "./router";
import store from "./store";

router.beforeEach((to,from,next) =>{
    //to: 表示跳转的目标路由对象
    //from: 表示跳转前的路由对象
    //next: 必须调用,表示可以进行路由跳转

    //引入判断对象
    if(store.getters.token){
        if(to.path === '/login'){
            next('/')
        }else{
            next()
        }
    }else{
        const whiteList = ['/login','/404']
        if(whiteList.indexOf(to.path) !== -1){
            next()
        }else{
            next('/login')
        }
    }
})